import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:jpush_flutter/jpush_interface.dart';

class MockJPushFlutterInterface extends JPushFlutterInterface {
  @override
  Future<Map<dynamic, dynamic>> getAllTags() async {
    return {'result': true, 'tags': ['tag1', 'tag2']};
  }

   @override
  Future<Map<dynamic, dynamic>> getAlias() async {
    return {'result': true, 'alias': 'alias'};
  }

   @override
  Future<String> getRegistrationID() async {
    return '1234567890abcdef';
  }
}

void main() {
  const MethodChannel channel = MethodChannel('jpush');
  late JPushFlutterInterface jpush;

  TestWidgetsFlutterBinding.ensureInitialized();

  setUp(() {
    jpush = MockJPushFlutterInterface();
    
    channel.setMockMethodCallHandler((MethodCall methodCall) async {
      switch (methodCall.method) {
        case 'getAlias':
          return {'alias': '1234567890abcdef', 'result': true};
        case 'getRegistrationId':
        case 'getRegistrationID':
          return '1234567890abcdef';
        case 'getAllTags':
          return {'tags': ['tag1', 'tag2'], 'result': true};
        default:
          return null;
      }
    });
  });

  tearDown(() {
    channel.setMockMethodCallHandler(null);
  });

  test('getAllTags', () async {
    final result = await jpush.getAllTags();
    expect(result, isNotNull);
    expect(result['tags'], isNotNull);
  });

   test('getRegistrationID', () async {
    final result = await jpush.getRegistrationID();
    expect(result, isNotNull);
  });

   test('getAlias', () async {
    final result = await jpush.getAlias();
    expect(result, isNotNull);
    expect(result['alias'], isNotNull);
  });
}


